<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新增问答</title>
    <link rel="stylesheet" href="/js/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/common.css" media="all">
    <script src="/js/layui/layui.all.js"></script>
    <script src="/js/utils.js"></script>
    <script src="../js/verify.js"></script>
</head>
<body>
<form class="layui-form" style="padding-right: 20px;">
    <div class="layui-form-item">
        <label class="layui-form-label">招生问题</label>
        <div class="layui-input-block">
            <input type="text" id="question" name="question" required lay-verify="required" placeholder="招生问题" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">答案</label>
        <div class="layui-input-block">
            <textarea placeholder="答案" id="answen" name="answen" required lay-verify="required" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="tijiao">提交</button>
            <button class="layui-btn" id="close" lay-filter="close">关闭</button>
        </div>
    </div>
</form>
</body>
<script>
    var $ = layui.$,form= layui.form,layer=layui.layer;
    var zxid = getQueryVariable('zxid');
    $.ajax({
        url:"/zixun/getDetail",
        data:{"zxid":zxid},
        success:function (res) {
            if(res.code==200){
                let obj = res.data;
                $("#zxname").val(obj.zxname);
                $("#zxphone").val(obj.zxphone);
                $("#zxqq").val(obj.zxqq);
                $("#school").val(obj.zxschool);
                if(obj.jiedairen!=null)
                {
                    $("#linkname").val(obj.jiedairen.jdname);
                }else{
                    let id = localStorage.getItem("kefu_id");
                    $("#linkman").val(id);
                }
                $("#zxtime").val(obj.zxtime);
                $("#zxmsg").val(obj.zxmsg);
                $("#zxmajor").val(obj.zxmajor);
                $("#zxemail").val(obj.zxemail);
                $("#zxintent").val(obj.zxintent);
                $("#remark").val(obj.zxremark);
            }
        }
    })
    $("#close").click(function (data) {
        parent.layui.layer.closeAll();
        return false;
    })
    form.on("submit(tijiao)",function (data) {
        data.field.zxid= zxid;
        data.field.question =  replaceReg(data.field.question);  // 替换
        data.field.answen =  replaceReg(data.field.answen);  // 替换
        layer.confirm('确定提交数据?', {icon: 3, title:'提示'}, function(index){
            $.ajax({
                url:"/wenda/add",
                type:"post",
                contentType:"application/json",
                data:JSON.stringify(data.field),
                success:function (res) {
                    console.log(res);
                    if(res.code==200){
                        layer.msg("添加成功");
                        setTimeout(function () {
                            parent.layui.layer.closeAll();
                        },500)
                    }else{
                        layer.msg(res.msg);
                    }
                }
            })
            layer.close(index);
        });
        return false;
    })
</script>
</html>